<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>attachEvent与addEventListener区别</title>
    <style type="text/css">

    </style>
</head>

<body>
    <button id="btn1">点我</button>

</body>
<script type="text/javascript">
    var btn1Obj = document.getElementById("btn1");

    function method1(){
        alert("method1");
    }
    function method2(){
        alert("method2");
    }
    function method3(){
        alert("method3");
    }
    function attachEventListen(obj,e,fun){
        /*obj.attachEvent ? obj.attachEvent("on"+e,fun) : obj.addEventListener(e,fun,false);*/
        obj.attachEvent("on"+e,fun);//测试浏览器，发现：firefox、chrome、IE9、IE10、IE11、safari、opera都不兼容,IE7、IE8兼容，
        //obj.addEventListener(e,fun,false);//测试浏览器，发现：firefox、chrome、IE、safari、opera都兼容，IE7、IE8不兼容，

    }

    attachEventListen(btn1Obj,"click",method1);
    attachEventListen(btn1Obj,"click",method2);
    attachEventListen(btn1Obj,"click",method3);

</script>
</html>